﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace WeixinSDK
{
    class WxJson
    {
        readonly static JsonSerializerSettings settings;

        static WxJson()
        {
            settings = new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore,
            };
        }

        public string SerializeObject()
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(this, settings);
        }

        public static string SerializeObject(object value)
        {

            return Newtonsoft.Json.JsonConvert.SerializeObject(value, settings);
        }

        public static T DeserializeObject<T>(string json) where T : WxError
        {
            var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(json);
            obj.OriginalJson = json;
            return obj;
        }
    }
}
